package com.imooc.mall.util;

import com.imooc.mall.common.Constant;
import org.apache.tomcat.util.codec.binary.Base64;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 加密工具
 */
public class MD5Utils {
    public static String getMD5Str(String string) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] digest1 = md5.digest((string + Constant.SALT).getBytes());
        return Base64.encodeBase64String(digest1);
    }

    /**
     * 测试 md5 值
     * @param args args
     * @throws NoSuchAlgorithmException NoSuchAlgorithmException
     */
    public static void main(String[] args) throws NoSuchAlgorithmException {
        String md5Str = getMD5Str("123");
        System.out.println(md5Str);
    }
}
